const Router = require('@koa/router')
const router = new Router({
  prefix: '/api/v1/ai'
})

const OpenAI = require("openai");

const openai = new OpenAI({
  //baseURL: 'https://api.deepseek.com/v1',
  //apiKey: 'sk-4be65992833c4385916d85b07b96b5a3'
  baseURL: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
  apiKey: 'sk-17ea31be23c343ee9e81f04a3164dff4'
});

router.get('/chat', async (ctx) => {
  const text = ctx.query.text
  console.log(text);

  const completion = await openai.chat.completions.create({
    //model: "qwen-plus", //  通义千问-plus
    model: "deepseek-r1",  // 模型列表：https://help.aliyun.com/zh/model-studio/getting-started/models
    messages: [
      { role: "system", content: "You are a helpful assistant." },
      { role: "user", content: text }
    ],
    //messages: [{ role: "system", content: "You are a helpful assistant." }],
    //model: "deepseek-chat", //  DeepSeek-V3
    //model: "deepseek-reasoner", //  DeepSeek-R1 推理模型
  });

  ctx.body = {
    code: 200,
    data: {
      role: 'assistant',
      content: completion.choices[0].message.content
    },
    message: 'Success'
  }
})

module.exports = router